package com.example.iread.http;

import com.example.iread.application.MyApplication;
import com.example.iread.bean.ResponseBean;
import com.example.iread.util.HttpUtil;

import java.util.concurrent.ThreadPoolExecutor;
import java.util.function.Consumer;

public class ChapterApi {

    private static final ThreadPoolExecutor threadPoolExecutor = MyApplication.getInstance().threadPoolExecutor;


    public static ResponseBean getByBookId(int pageNum, int pageSize, int bookId) {
        return HttpUtil.doGet(String.format("/api/chapter/getByBookId/%s?pageNum=%s&pageSize=%s", bookId, pageNum, pageSize));
    }

    public static void getByBookId(int pageNum, int pageSize, int bookId, Consumer<ResponseBean> consumer) {
        threadPoolExecutor.execute(() -> consumer.accept(getByBookId(pageNum, pageSize, bookId)));
    }

    public static ResponseBean getById(int chapterId) {
        return HttpUtil.doGet(String.format("/api/chapter/getById/%s", chapterId));
    }

    public static void getById(int chapterId, Consumer<ResponseBean> consumer) {
        threadPoolExecutor.execute(() -> consumer.accept(getById(chapterId)));
    }

    public static ResponseBean getCountByBookId(int bookId) {
        return HttpUtil.doGet("/api/chapter/getCountByBookId/" + bookId);
    }

    public static void getCountByBookId(int bookId, Consumer<ResponseBean> consumer) {
        threadPoolExecutor.execute(() -> consumer.accept(getCountByBookId(bookId)));
    }

}
